package com.wangzhixuan.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wangzhixuan.commons.base.BaseController;
import com.wangzhixuan.commons.result.PageInfo;
import com.wangzhixuan.commons.utils.ResponseUtil;
import com.wangzhixuan.commons.utils.StringUtils;
import com.wangzhixuan.model.Product;
import com.wangzhixuan.model.vo.ProductVo;
import com.wangzhixuan.service.ProductService;


/** 
 * @author: thomas121124
 * @date: 2018年7月10日 下午7:10:13 
 * @Description: 产品controller
 */
@Controller
@RequestMapping(value = "/product")
public class ProductController extends BaseController{
	
	@Autowired
	private ProductService productService;
	
	 /**
     * 产品主页
     *
     * @return
     */
    @GetMapping(value = "/manager")
    public String manager() {
        return "admin/product/productSearch";
    }
	
	@RequestMapping("/dataGrid")
	@ResponseBody
	public Object dataGrid(ProductVo productVo, Integer page, Integer rows, String sort, String order) throws Exception{
		
		PageInfo pageInfo = new PageInfo(page, rows,sort,order);
        Map<String, Object> condition = new HashMap<String, Object>();

        if (StringUtils.isNotBlank(productVo.getProductName())) {
            condition.put("productName", productVo.getProductName());
        }
        if(StringUtils.isNotBlank(productVo.getModel())){
        	condition.put("model", productVo.getModel());
        }
        if(productVo.getPrice() != null){
        	condition.put("price", productVo.getPrice());
        }
        if(productVo.getStore() != null){
        	condition.put("store", productVo.getStore());
        }
        if (productVo.getCreatedateStart() != null) {
            condition.put("startTime", productVo.getCreatedateStart());
        }
        if (productVo.getCreatedateEnd() != null) {
            condition.put("endTime", productVo.getCreatedateEnd());
        }
        
        pageInfo.setCondition(condition);
        productService.selectDataGrid(pageInfo);
        return pageInfo;
	}
	

	
	

}
